package com.rongshu.view.penpal.activity;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.eventbus.SearchPenpalArticleMode;
import com.rongshu.utils.Constant;
import com.rongshu.view.base.BaseActivity;
import com.widget.EditTextWithDel;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * created by zhengweis on 2018/11/1.
 * description：搜索
 */
public class SearchActivity extends BaseActivity {


    @BindView(R.id.search_left_tv)
    EditTextWithDel searchLeftTv;
    private int penpalId;

    @Override
    protected int initLayout() {
        return R.layout.activity_base_search;
    }

    @Override
    protected void initView() {
        searchLeftTv.setHint("请输入关键字");
        Intent intent = getIntent();
        if (intent != null) {
            penpalId = intent.getIntExtra(Constant.PENPAL_ID, 0);
        }
        searchLeftTv.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    showKeyboard(false);
                    Intent intent = new Intent(SearchActivity.this, PenpalSearchArticleActivity.class);
                    String msg = v.getText().toString();
                    SearchPenpalArticleMode searchMode = new SearchPenpalArticleMode();
                    searchMode.setPenpalId(penpalId);
                    searchMode.setContent(msg);
                    intent.putExtra(Constant.INTENT_DATA, searchMode);
                    startActivity(intent);
                }
                return false;
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    @OnClick({R.id.search_right_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.search_right_tv:
                showKeyboard(false);
                finish();
                break;
        }
    }
}
